//
//  AssetAController.m
//  FinancialProduct
//  现金管理详情
//  Created by Stella on 2017/9/4.
//  Copyright © 2017年 maq. All rights reserved.
//

#import "HandleNetProduct.h"
#import "MyAccountCell.h"
#import "CKPuslichTool.h"
#import "RecordListController.h"
#import "AssetAController.h"
#import "UserModel.h"
#import "ReportController.h"
#import "UserBankAccountController.h"
#import "InspectController.h"

@interface AssetAController ()
@property (weak, nonatomic) IBOutlet UITableView *mTableView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property(nonatomic,strong)NSMutableArray *DataArray;
@property(nonatomic,strong)NSMutableArray *infoArray;
@property(nonatomic,strong)NSDictionary *info;
@property(nonatomic,strong)NSArray *bottomArray;
@end

@implementation AssetAController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"详细信息";
    _DataArray = [[NSMutableArray alloc] init];
    _infoArray = [[NSMutableArray alloc] init];
    
    if ([_infoDic[@"ContractStatus"] isEqualToString:@"存续"]) {
        _bottomArray = @[@"交易记录",@"受益账户",@"产品报告",@"产品公告"];
    }else{
        _bottomArray = @[@"交易记录",@"受益账户"];
    }
    [self getDetailInfo];
    // Do any additional setup after loading the view.
    
    _bottomView.hidden = YES;
    if ([_infoDic[@"ProductTypeLevel1"] isEqualToString:@"二级市场"]) {
        _bottomView.hidden = NO;
    }
}
-(void)getDetailInfo{
    /*
     * Contractno 产品合同号
     * CurrencyType 币种
     * Templet 模板
     */
    UserModel *model=[UserModel getUser];
    int mid=[model.CustomerID intValue];
    NSDictionary *params=@{@"AAAMethodName":@"Prodetail",@"CustomerID":@(mid),
                         
                           @"Contractno":self.infoDic[@"Contractno"],
                           @"CurrencyType":self.infoDic[@"CurrencyType"],
                           @"Templet":self.infoDic[@"Templet"]};
    //NSLog(@"params===%@",params);
    [HandleNetProduct getListforParams:params Success:^(NSArray *data) {
        if (data.count>0) {
            NSDictionary *dicct=data[0];
            /***
             **/
            self.info=dicct;
            
            [_DataArray addObjectsFromArray:@[@"产品成立日/开放日",@"初始投资金额",@"初始基金份额",@"基金份额类型",@"期限",@"业绩比较基准",@"预计清算日期",@"已分配本金",@"已分配收益"]];
            [_infoArray addObjectsFromArray:@[dicct[@"qPlacementDate"],
                                              dicct[@"qInitalAmount"],
                                              dicct[@"qInitialshare"],
                                              dicct[@"BenefitType"],
                                              dicct[@"ProductPeriodShow"],
                                              dicct[@"ExpectedRate"],
                                              dicct[@"qAExpectedDueDate"],
                                              dicct[@"qBJAmt"],
                                              dicct[@"qSYAmt"]]];
            if ([dicct[@"Isshow"] isEqualToString:@"是"]) {
                [_DataArray addObject:@"数据截止日期"];
                [_infoArray addObject:dicct[@"DatacutoffDate"]];
            }
            
            
        }
        [self.mTableView reloadData];
    } Failure:^(NSString *errorInfo) {
        
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50
    ;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 2;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section==0) {
        return self.DataArray.count;
    }
    return _bottomArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell0" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.unit.text=@"";
        if (indexPath.row==1||indexPath.row==7||indexPath.row==8) {
            cell.unit.text=@"万元";
        }
        if (indexPath.row==2) {
            cell.unit.text=@"份";
        }
        if (indexPath.row==5) {
            cell.unit.text=@"";
        }
//        if (indexPath.row==0||indexPath.row==3||indexPath.row==6) {
//            cell.RightLabel.textColor=[UIColor blackColor];
//        }
        cell.NameLabel.text=self.DataArray[indexPath.row];
        cell.RightLabel.text=self.infoArray[indexPath.row];
        return cell;
    }
    MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryNone;
//    if (indexPath.row==0) {
//        cell.NameLabel.text=@"交易记录";
//    }else{
//       cell.NameLabel.text=@"受益账户";
////        cell.RightLabel.text=self.info[@"Bank"];
//    }
    cell.NameLabel.text=_bottomArray[indexPath.row];
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section==1) {
        if (indexPath.row==0) {
            //交易记录
            RecordListController *vc=(RecordListController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"RecordListController"];
            vc.infoDic=self.infoDic;
            [self.navigationController pushViewController:vc animated:YES];
        }else if (indexPath.row==1){
            //受益账户
            UserBankAccountController *vc=(UserBankAccountController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"UserBankAccountController"];
            vc.infoDic=self.info;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            ReportController *vc=(ReportController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"ReportController"];
            if (indexPath.row==2) {
                vc.title=@"产品报告";
            }else{
                vc.title=@"产品公告";
            }
            
            vc.ProductId=self.infoDic[@"ProductID"];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

- (IBAction)clickJianShiAction:(UIButton *)sender {
    InspectController *vc=(InspectController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"InspectController"];
    vc.productId = _infoDic[@"ProductID"];
    vc.customerID = _infoDic[@"CustomerID"];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
